﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GUILibrary;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace MapLibrary.GUI
{
    /// <summary>
    /// This class represents the whole GUI screen for upgrading
    /// your skills.  This means it contains individual SkillUpgradePanels
    /// for upgrading each individual skill.
    /// </summary>
    public class SkillUpgradeGUI : GUIScreen
    {

        private Vector2 GUI_LOCATION = new Vector2(100, 100);
        private const int PANEL_PADDING_X = 50;
        private const int NUM_PANELS = 3;

        /// <summary>
        /// These panels control the upgrading of individual skills
        /// </summary>
        private SkillUpgradePanel[] skillUpgradePanels;

        /// <summary>
        /// A reference to the game's world (needed to access player data).
        /// </summary>
        private GameWorld world;

        public SkillUpgradeGUI(GameWorld world)
        {
            this.world = world;
            this.skillUpgradePanels = new SkillUpgradePanel[NUM_PANELS];
        }

        /// <summary>
        /// Initialize the SKillUpgradeGUI by building the panels.
        /// </summary>
        /// <param name="manager"></param>
        public void Initialize(ContentManager manager)
        {
            BuildPanels();
            LoadPanels(manager);
            RegisterPanels();
        }

        /// <summary>
        /// Build the list of SkillUpgradePanels.
        /// </summary>
        /// <param name="cm"></param>
        private void BuildPanels()
        {
            int i = 0;

            skillUpgradePanels[i] = new SkillUpgradePanel(
                world,
                GUI_LOCATION + (i++ * new Vector2(0, SkillUpgradePanel.PANEL_HEIGHT)),
                "PowerShield");

            skillUpgradePanels[i] = new SkillUpgradePanel(
                world,
                GUI_LOCATION + (i++ * new Vector2(0, SkillUpgradePanel.PANEL_HEIGHT)),
                "Explosion");

            skillUpgradePanels[i] = new SkillUpgradePanel(
                world,
                GUI_LOCATION + (i++ * new Vector2(0, SkillUpgradePanel.PANEL_HEIGHT)),
                "Net");
        }

        /// <summary>
        /// Load the data for all of the SkillUpgradePanels.
        /// </summary>
        /// <param name="cm"></param>
        private void LoadPanels(ContentManager cm)
        {
            for (int i = 0; i < NUM_PANELS; i++)
            {
                skillUpgradePanels[i].Load(cm);
            }
        }

        /// <summary>
        /// Register the created SkillUpgradePanels to this GUIScreen.  This
        /// means the panels add their buttons and backdrops to the buttons and
        /// backdrops lists of this GUIScreen for rendering and action resolution.
        /// </summary>
        private void RegisterPanels()
        {
            for (int i = 0; i < NUM_PANELS; i++)
            {
                skillUpgradePanels[i].RegisterToScreen(this);
            }
        }
    }
}
